package com.hnguigu.controller;

import com.hnguigu.Users;
import com.hnguigu.service.impl.UserServiceImpl;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("user")
public class UserLoginController {
@Autowired
    UserServiceImpl userService;
    @RequestMapping("login")
    public String USerLogin( Users users) {
        try {
            Subject subject = SecurityUtils.getSubject();
            UsernamePasswordToken token = new UsernamePasswordToken(users.getUserName(), users.getUserPwd());
            subject.login(token);
        } catch (Exception e) {
            System.out.println("帐号密码错误");
            return "/login.html";
        }
        return "/home.html";
    }
    @RequestMapping("test1")
    public void test1(){
        System.out.println("test1");

    }
    @RequestMapping("test2")
    public void test2(){
        System.out.println("test2");

    }
    @RequestMapping("test3")
    public String test3(){
       try {
            userService.tm();
           System.out.println("");
       }catch (Exception e){
           return  "/error.html";
       }
            return "";
    }
}